package com.jweb.framework.security.crypto.cipher.symmetric;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

import org.springframework.beans.factory.InitializingBean;

import com.jweb.framework.security.crypto.common.EAlgorithm;

/**
 * 修改人： Thomas
 * 修改内容：新增 
 * 类说明：默认KEY生成器
 */
public class DefaultKeyGenerator implements KeyGenerator , InitializingBean {
	
	protected javax.crypto.KeyGenerator generator ;
	protected EAlgorithm algorithm = EAlgorithm.DES ;
	
	public byte[] generate(){
		return this.generator.generateKey().getEncoded() ;
	}

	@Override
	public void afterPropertiesSet() throws NoSuchAlgorithmException {
		this.generator = javax.crypto.KeyGenerator.getInstance(this.algorithm.toString());
		
		this.generator.init(new SecureRandom());
	}
	
	public void setAlgorithm(EAlgorithm ealgorithm){
		this.algorithm = ealgorithm ;
	}

}
